package com.gdth.bank.service;

import java.util.ArrayList;
import java.util.List;

import com.gdth.bank.BankApplication;
import com.gdth.bank.utils.AppUtil;
import com.gdth.database.bean.DaoSession;
import com.gdth.database.bean.TAppBfrjBfjl;
import com.gdth.database.bean.TAppBfrjBfjlDao;
import com.gdth.database.bean.TAppBfrjCpxq;
import com.gdth.database.bean.TAppBfrjCpxqDao;
import com.gdth.database.bean.TAppBfrjJbxxb;
import com.gdth.database.bean.TAppBfrjJbxxbDao;
import com.gdth.database.bean.TAppBfrjJtcyb;
import com.gdth.database.bean.TAppBfrjJtcybDao;
import com.gdth.database.bean.TAppBfrjLxfs;
import com.gdth.database.bean.TAppBfrjLxfsDao;
import com.gdth.database.bean.TAppBfrjThjl;
import com.gdth.database.bean.TAppBfrjThjlDao;
import com.gdth.database.bean.TAppBfrjZcxxb;
import com.gdth.database.bean.TAppBfrjZcxxbDao;
import com.gdth.database.bean.TAppFjxxb;
import com.gdth.database.bean.TAppFjxxbDao;
import com.gdth.utils.GsonUtil;
import com.gdth.utils.ToolUtil;

import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;


public class CjkhjlService {
	/**
	 * 根据状态获取采集基本信息表
	 * @return
	 */
	public List<TAppBfrjJbxxb> getAllBfrjByZt(){
		List<TAppBfrjJbxxb> mList = new ArrayList<TAppBfrjJbxxb>();
		
		//获取需要上传的客户信息
		TAppBfrjJbxxbDao dao = BankApplication.getDaoSession().getTAppBfrjJbxxbDao();
		QueryBuilder<TAppBfrjJbxxb> qb = dao.queryBuilder();
		
		qb.where(TAppBfrjJbxxbDao.Properties.Sjzt.notEq(AppUtil.sjzt_normal),TAppBfrjJbxxbDao.Properties.Sjzt.notEq(AppUtil.sjzt_delete));
		mList = qb.list();
		
		//获取详细信息
		for (TAppBfrjJbxxb mTAppBfrjJbxxb : mList){
			mTAppBfrjJbxxb = getBfrjForDetail(mTAppBfrjJbxxb);
		}
		return mList;
	}
	
	
	/**
	 * 根据状态获取采集基本信息表
	 * @return
	 */
	public List<TAppBfrjJbxxb> getOneBfrjByZt(String uuid){
		List<TAppBfrjJbxxb> mList = new ArrayList<TAppBfrjJbxxb>();
		
		//获取需要上传的客户信息
		TAppBfrjJbxxbDao dao = BankApplication.getDaoSession().getTAppBfrjJbxxbDao();
		QueryBuilder<TAppBfrjJbxxb> qb = dao.queryBuilder();
		
		qb.where(TAppBfrjJbxxbDao.Properties.Uuid.eq((uuid)));
		mList = qb.list();
		
		//获取详细信息
		for (TAppBfrjJbxxb mTAppBfrjJbxxb : mList){
			mTAppBfrjJbxxb = getBfrjForDetail(mTAppBfrjJbxxb);
		}
		return mList;
	}
	
	/**
	 * 获取所有子表信息
	 * @param mTAppBfrjJbxxb
	 * @return
	 */
	private TAppBfrjJbxxb getBfrjForDetail(TAppBfrjJbxxb mTAppBfrjJbxxb){
		String jcuuid = mTAppBfrjJbxxb.getUuid();
		DaoSession session = BankApplication.getDaoSession();
		
		TAppBfrjBfjlDao bfjlDao = session.getTAppBfrjBfjlDao();
		TAppBfrjJtcybDao jtcyDao = session.getTAppBfrjJtcybDao();
		TAppBfrjCpxqDao cpxqDao = session.getTAppBfrjCpxqDao();
		TAppBfrjZcxxbDao zcxxDao = session.getTAppBfrjZcxxbDao();
		TAppBfrjLxfsDao lxfsDao = session.getTAppBfrjLxfsDao();
		TAppBfrjThjlDao thjlDao = session.getTAppBfrjThjlDao();
		
		//查询拜访信息
		QueryBuilder<TAppBfrjBfjl> bfrjqb = bfjlDao.queryBuilder();
		bfrjqb.where(TAppBfrjBfjlDao.Properties.Jcuuid.eq(jcuuid), 
				bfrjqb.or(TAppBfrjBfjlDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjBfjlDao.Properties.Sjzt.eq(AppUtil.sjzt_update),TAppBfrjBfjlDao.Properties.Sjzt.eq(AppUtil.sjzt_delete)));
		List<TAppBfrjBfjl> bfjList = bfrjqb.list();
		mTAppBfrjJbxxb.setBfjls(bfjList);
//		mTAppBfrjJbxxb.getBfjls().addAll(bfjList);
//		查询家庭信息
		QueryBuilder<TAppBfrjJtcyb> jtcyqb = jtcyDao.queryBuilder();
		jtcyqb.where(TAppBfrjJtcybDao.Properties.Jcuuid.eq(jcuuid), 
				jtcyqb.or(TAppBfrjJtcybDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjJtcybDao.Properties.Sjzt.eq(AppUtil.sjzt_update),TAppBfrjJtcybDao.Properties.Sjzt.eq(AppUtil.sjzt_delete)));
		List<TAppBfrjJtcyb> jtcyList = jtcyqb.list();
		mTAppBfrjJbxxb.setJtcys(jtcyList);
//		mTAppBfrjJbxxb.getJtcys().addAll(jtcyList);
//		查询家庭信息
		QueryBuilder<TAppBfrjCpxq> cpxqqb = cpxqDao.queryBuilder();
		cpxqqb.where(TAppBfrjCpxqDao.Properties.Jcuuid.eq(jcuuid), 
				cpxqqb.or(TAppBfrjCpxqDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjCpxqDao.Properties.Sjzt.eq(AppUtil.sjzt_delete)));
		List<TAppBfrjCpxq> cpxqList = cpxqqb.list();
		mTAppBfrjJbxxb.setCpxqs(cpxqList);
//		mTAppBfrjJbxxb.getCpxqs().addAll(cpxqList);
//		资产信息
		QueryBuilder<TAppBfrjZcxxb> zcxxqb = zcxxDao.queryBuilder();
		zcxxqb.where(TAppBfrjZcxxbDao.Properties.Jcuuid.eq(jcuuid), 
				zcxxqb.or(TAppBfrjZcxxbDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjZcxxbDao.Properties.Sjzt.eq(AppUtil.sjzt_update), TAppBfrjZcxxbDao.Properties.Sjzt.eq(AppUtil.sjzt_delete)));
		List<TAppBfrjZcxxb> zcxxList = zcxxqb.list();
		mTAppBfrjJbxxb.setZcxxs(zcxxList);
//		mTAppBfrjJbxxb.getZcxxs().addAll(zcxxList);
//		联系方式
		QueryBuilder<TAppBfrjLxfs> lxfsqb = lxfsDao.queryBuilder();
		lxfsqb.where(TAppBfrjLxfsDao.Properties.Jcuuid.eq(jcuuid), 
				lxfsqb.or(TAppBfrjLxfsDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjLxfsDao.Properties.Sjzt.eq(AppUtil.sjzt_update)));
		List<TAppBfrjLxfs> lxfsList = lxfsqb.list();
		mTAppBfrjJbxxb.setLxfss(lxfsList);
//		mTAppBfrjJbxxb.getLxfss().addAll(lxfsList);
//		通话方式
		QueryBuilder<TAppBfrjThjl> thjlqb = thjlDao.queryBuilder();
		thjlqb.where(TAppBfrjThjlDao.Properties.Jcuuid.eq(jcuuid), 
				thjlqb.or(TAppBfrjThjlDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjThjlDao.Properties.Sjzt.eq(AppUtil.sjzt_update)));
		List<TAppBfrjThjl> thjlList = thjlqb.list();
		
		mTAppBfrjJbxxb.setThjls(thjlList);
//		mTAppBfrjJbxxb.getThjls().addAll(thjlList);
		return mTAppBfrjJbxxb;
	}

	/**
	 * 保存采集客户信息
	 * @param mList
	 */
	public void saveAllBfrj(List<TAppBfrjJbxxb> mList) {

		for (TAppBfrjJbxxb mTAppBfrjJbxxb : mList) {
			//mTAppBfrjJbxxb.setId(null);
			saveBfrj(mTAppBfrjJbxxb);
		}
	}

	/**
	 * 保存单个采集客户信息
	 * @param mTAppBfrjJbxxb
	 */
	private void saveBfrj(TAppBfrjJbxxb mTAppBfrjJbxxb) {
		DaoSession session = BankApplication.getDaoSession();
		session.clear();
		TAppBfrjJbxxbDao dao = session.getTAppBfrjJbxxbDao();

		String jcuuid = mTAppBfrjJbxxb.getUuid();
		QueryBuilder<TAppBfrjJbxxb> jcxxQb = dao.queryBuilder();
		jcxxQb.where(TAppBfrjJbxxbDao.Properties.Uuid.eq(jcuuid)).build();
		List<TAppBfrjJbxxb> jcxxs = jcxxQb.list();
		mTAppBfrjJbxxb.setSjzt(AppUtil.sjzt_normal);
		if (jcxxs.size() > 0) {
			mTAppBfrjJbxxb.setId(jcxxs.get(0).getId());
		} else {
			mTAppBfrjJbxxb.setId(null);
		}

		dao.insertOrReplace(mTAppBfrjJbxxb);
		//dao.insertOrReplace();

		String uuid = "";

		//保存所有拜访日志
//		这是过滤，在这里打断点测试
		List<TAppBfrjBfjl> bfjls = mTAppBfrjJbxxb.getBfjls();
		if (bfjls != null) {
			TAppBfrjBfjlDao mDao = session.getTAppBfrjBfjlDao();
			//QueryBuilder<TAppBfrjBfjl> query = mDao.queryBuilder();
			
			for (TAppBfrjBfjl obj : bfjls) {
				uuid = obj.getUuid();
				//query.where(TAppBfrjBfjlDao.Properties.Uuid.eq(uuid)).build();
				Query<TAppBfrjBfjl> query = mDao.queryBuilder().where(TAppBfrjBfjlDao.Properties.Uuid.eq(uuid)).build();
				
				List<TAppBfrjBfjl> mList = query.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}

				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有家庭成员
		List<TAppBfrjJtcyb> jtcys = mTAppBfrjJbxxb.getJtcys();
		if (jtcys != null) {
			TAppBfrjJtcybDao mDao = session.getTAppBfrjJtcybDao();
			//QueryBuilder<TAppBfrjJtcyb> query = mDao.queryBuilder();

			for (TAppBfrjJtcyb obj : jtcys) {
				uuid = obj.getUuid();
			//	query.where(TAppBfrjJtcybDao.Properties.Uuid.eq(uuid));
				Query<TAppBfrjJtcyb> queryTwo = mDao.queryBuilder().where(TAppBfrjJtcybDao.Properties.Uuid.eq(uuid)).build();
				List<TAppBfrjJtcyb> mList = queryTwo.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}
				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有产品意向
		List<TAppBfrjCpxq> cpxqs = mTAppBfrjJbxxb.getCpxqs();
		if (cpxqs != null) {
			TAppBfrjCpxqDao mDao = session.getTAppBfrjCpxqDao();
			//QueryBuilder<TAppBfrjCpxq> query = mDao.queryBuilder();
			
			for (TAppBfrjCpxq obj : cpxqs) {
				uuid = obj.getUuid();
				//query.where(TAppBfrjCpxqDao.Properties.Uuid.eq(uuid)).build();
				Query<TAppBfrjCpxq> query = mDao.queryBuilder().where(TAppBfrjCpxqDao.Properties.Uuid.eq(uuid)).build();

				
				List<TAppBfrjCpxq> mList = query.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}

				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有资产信息
		List<TAppBfrjZcxxb> zcxxs = mTAppBfrjJbxxb.getZcxxs();
		if (zcxxs != null) {
			TAppBfrjZcxxbDao mDao = session.getTAppBfrjZcxxbDao();
			//QueryBuilder<TAppBfrjZcxxb> query = mDao.queryBuilder();
			
			for (TAppBfrjZcxxb obj : zcxxs) {
				uuid = obj.getUuid();
				//query.where(TAppBfrjZcxxbDao.Properties.Uuid.eq(uuid)).build();
				
				Query<TAppBfrjZcxxb> query = mDao.queryBuilder().where(TAppBfrjZcxxbDao.Properties.Uuid.eq(uuid)).build();

				List<TAppBfrjZcxxb> mList = query.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}

				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有联系方式
		List<TAppBfrjLxfs> lxfss = mTAppBfrjJbxxb.getLxfss();
		if (lxfss != null) {
			TAppBfrjLxfsDao mDao = session.getTAppBfrjLxfsDao();
			//QueryBuilder<TAppBfrjLxfs> query = mDao.queryBuilder();
			
			for (TAppBfrjLxfs obj : lxfss) {
				uuid = obj.getUuid();
				//query.where(TAppBfrjLxfsDao.Properties.Uuid.eq(uuid)).build();
				
				Query<TAppBfrjLxfs> query = mDao.queryBuilder().where(TAppBfrjLxfsDao.Properties.Uuid.eq(uuid)).build();

				
				List<TAppBfrjLxfs> mList = query.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}

				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有通话记录
		List<TAppBfrjThjl> thjls = mTAppBfrjJbxxb.getThjls();
		if (thjls != null) {
			TAppBfrjThjlDao mDao = session.getTAppBfrjThjlDao();
			//QueryBuilder<TAppBfrjThjl> query = mDao.queryBuilder();
			
			for (TAppBfrjThjl obj : thjls) {
				uuid = obj.getUuid();
				//query.where(TAppBfrjThjlDao.Properties.Uuid.eq(uuid)).build();
				
				Query<TAppBfrjThjl> query = mDao.queryBuilder().where(TAppBfrjThjlDao.Properties.Uuid.eq(uuid)).build();				
				List<TAppBfrjThjl> mList = query.list();
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
				}

				obj.setSjzt(AppUtil.sjzt_normal);
				mDao.insertOrReplace(obj);
			}
		}
		//保存所有附件信息
		List<TAppFjxxb> fjxxs = mTAppBfrjJbxxb.getFjxxs();
		if (fjxxs != null) {
			TAppFjxxbDao mDao = session.getTAppFjxxbDao();
			//QueryBuilder<TAppFjxxb> query = mDao.queryBuilder();
			
			for (TAppFjxxb obj : fjxxs) {
				uuid = obj.getUuid();
				//query.where(TAppFjxxbDao.Properties.Uuid.eq(uuid)).build();
				Query<TAppFjxxb> query = mDao.queryBuilder().where(TAppFjxxbDao.Properties.Uuid.eq(uuid)).build();

				List<TAppFjxxb> mList = query.list();
				
				/*附件关联的主表uuid出现重复后，同步附件表原注释代码保存会出现Cannot update entity without key - was it inserted before，
				 * 最根还是要解决保存出现重复生成uuid问题*/
				/*if (mList.size() > 0) {
//					obj.setId(mList.get(0).getId());
//					obj.setUuid(uuid);
					mDao.update(obj);
				} else {
//					obj.setId(null);
					obj.setUuid(uuid);
					obj.setAppdz(ToolUtil.getFilePath(obj.getUuid() + "." + obj.getWjlx()));
					obj.setSczt(2);
					obj.setGnmk(1);
					mDao.insertOrReplace(obj);
				}*/
				if (mList.size() > 0) {
					obj.setId(mList.get(0).getId());
				} else {
					obj.setId(null);
					obj.setUuid(uuid);
					obj.setAppdz(ToolUtil.getFilePath(obj.getUuid() + "." + obj.getWjlx()));
					obj.setSczt(2);
					obj.setGnmk(1);
				}
				mDao.insertOrReplace(obj);
			}
		}
	}

	public void updateBfrjZt(String json) {
		List<TAppBfrjJbxxb> beans = GsonUtil.getTAppBfrjJbxxbs(json);
		DaoSession session = BankApplication.getDaoSession();
		TAppBfrjJbxxbDao dao = session.getTAppBfrjJbxxbDao();
		QueryBuilder<TAppBfrjJbxxb> qb = dao.queryBuilder();

		for (TAppBfrjJbxxb bean : beans){
			String jcuuid = bean.getUuid();
			qb.where(TAppBfrjJbxxbDao.Properties.Uuid.eq(jcuuid));
			
			List<TAppBfrjJbxxb> mList = qb.list();
			for (TAppBfrjJbxxb mCjkhxx : mList) {
				
				
				//标识数据在上传过程未做修改
				boolean isUpdate = true;
				
				isUpdate = updateBfjlByZt(bean.getBfjls());
				isUpdate = updateJtcyByZt(bean.getJtcys());
				isUpdate = updateCpxqByZt(bean.getCpxqs());
				isUpdate = updateZcxxByZt(bean.getZcxxs());
				isUpdate = updateLxfsByZt(bean.getLxfss());
				isUpdate = updateThjlByZt(bean.getThjls());
				
				if (isUpdate) {
					mCjkhxx.setSjzt(AppUtil.sjzt_normal);
					if (mCjkhxx.getBbh() == bean.getBbh()) {
						mCjkhxx.setSjzt(AppUtil.sjzt_normal);
						
					}
				}
				
				dao.insertOrReplace(mCjkhxx);
			}
		}
		
	}
	
	/**
	 * 修改拜访记录状态
	 * @param mList
	 * @return
	 */
	private boolean updateBfjlByZt(List<TAppBfrjBfjl> mList) {
		boolean result = true;
		
		if (mList == null)
			return result;
		
		String uuid = "";
		int bbh = 0;

		TAppBfrjBfjlDao jtcyDao = BankApplication.getDaoSession().getTAppBfrjBfjlDao();
		QueryBuilder<TAppBfrjBfjl> jtcyQb = jtcyDao.queryBuilder();
		for (TAppBfrjBfjl obj : mList) {
			uuid = obj.getUuid();
			bbh = obj.getBbh();
			
			jtcyQb.where(TAppBfrjBfjlDao.Properties.Uuid.eq(uuid));
			List<TAppBfrjBfjl> list = jtcyQb.list();
			for (TAppBfrjBfjl mTAppBfrjBfjl : list) {
				if (mTAppBfrjBfjl.getBbh() == bbh) {
					if (mTAppBfrjBfjl.getSjzt() == AppUtil.sjzt_delete)
						mTAppBfrjBfjl.setSjzt(AppUtil.sjzt_cancel);
					else
						mTAppBfrjBfjl.setSjzt(AppUtil.sjzt_normal);
					
					jtcyDao.insertOrReplace(mTAppBfrjBfjl);
				} else {
					result = false;
				}
			}
		}
		
		return result;
	}
	
	/**
	 * 修改家庭成员状态
	 * @param jtcys
	 * @return
	 */
	private boolean updateJtcyByZt(List<TAppBfrjJtcyb> jtcys) {
		boolean result = true;
		
		if (jtcys == null)
			return result;
		
		String uuid = "";
		int bbh = 0;

		TAppBfrjJtcybDao jtcyDao = BankApplication.getDaoSession().getTAppBfrjJtcybDao();
		QueryBuilder<TAppBfrjJtcyb> jtcyQb = jtcyDao.queryBuilder();
		for (TAppBfrjJtcyb jtcy : jtcys) {
			uuid = jtcy.getUuid();
			bbh = jtcy.getBbh();
			
			jtcyQb.where(TAppBfrjJtcybDao.Properties.Uuid.eq(uuid));
			List<TAppBfrjJtcyb> list = jtcyQb.list();
			for (TAppBfrjJtcyb mTAppBfrjJtcyb : list) {
				if (mTAppBfrjJtcyb.getBbh() == bbh) {
					if (mTAppBfrjJtcyb.getSjzt() == AppUtil.sjzt_delete)
						mTAppBfrjJtcyb.setSjzt(AppUtil.sjzt_cancel);
					else
						mTAppBfrjJtcyb.setSjzt(AppUtil.sjzt_normal);

					jtcyDao.insertOrReplace(mTAppBfrjJtcyb);
				} else {
					result = false;
				}
			}
		}
		
		return result;
	}

	/**
	 * 修改产品意向状态
	 * @param mList
	 * @return
	 */
	private boolean updateCpxqByZt(List<TAppBfrjCpxq> mList) {
		boolean result = true;
		
		if (mList == null)
			return result;
		
		String uuid = "";
		int bbh = 0;

		TAppBfrjCpxqDao jtcyDao = BankApplication.getDaoSession().getTAppBfrjCpxqDao();
		QueryBuilder<TAppBfrjCpxq> jtcyQb = jtcyDao.queryBuilder();
		for (TAppBfrjCpxq obj : mList) {
			uuid = obj.getUuid();
			bbh = obj.getBbh();
			
			jtcyQb.where(TAppBfrjCpxqDao.Properties.Uuid.eq(uuid));
			List<TAppBfrjCpxq> list = jtcyQb.list();
			for (TAppBfrjCpxq mTAppBfrjCpxq : list) {
				if (mTAppBfrjCpxq.getBbh() == bbh) {
					mTAppBfrjCpxq.setSjzt(AppUtil.sjzt_normal);
					jtcyDao.insertOrReplace(mTAppBfrjCpxq);
				} else {
					result = false;
				}
			}
		}
		
		return result;
	}
	
	/**
	 * 修改资产信息状态
	 * @param mList
	 * @return
	 */
	private boolean updateZcxxByZt(List<TAppBfrjZcxxb> mList) {
		boolean result = true;
		
		if (mList == null)
			return result;
		
		String uuid = "";
		int bbh = 0;

		TAppBfrjZcxxbDao jtcyDao = BankApplication.getDaoSession().getTAppBfrjZcxxbDao();
		QueryBuilder<TAppBfrjZcxxb> jtcyQb = jtcyDao.queryBuilder();
		for (TAppBfrjZcxxb obj : mList) {
			uuid = obj.getUuid();
			bbh = obj.getBbh();
			
			jtcyQb.where(TAppBfrjZcxxbDao.Properties.Uuid.eq(uuid));
			List<TAppBfrjZcxxb> list = jtcyQb.list();
			for (TAppBfrjZcxxb mTAppBfrjZcxxb : list) {
				if (mTAppBfrjZcxxb.getBbh() == bbh) {
					if (mTAppBfrjZcxxb.getSjzt() == AppUtil.sjzt_delete)
						mTAppBfrjZcxxb.setSjzt(AppUtil.sjzt_cancel);
					else
						mTAppBfrjZcxxb.setSjzt(AppUtil.sjzt_normal);
					jtcyDao.insertOrReplace(mTAppBfrjZcxxb);
				} else {
					result = false;
				}
			}
		}
		
		return result;
	}
	
	/**
	 * 修改联系方式
	 * @param mList
	 * @return
	 */
	private boolean updateLxfsByZt(List<TAppBfrjLxfs> mList) {
		boolean result = true;
		
		if (mList == null)
			return result;
		
		String uuid = "";
		int bbh = 0;

		TAppBfrjLxfsDao jtcyDao = BankApplication.getDaoSession().getTAppBfrjLxfsDao();
		QueryBuilder<TAppBfrjLxfs> jtcyQb = jtcyDao.queryBuilder();
		for (TAppBfrjLxfs obj : mList) {
			uuid = obj.getUuid();
			bbh = obj.getBbh();
			
			jtcyQb.where(TAppBfrjLxfsDao.Properties.Uuid.eq(uuid));
			List<TAppBfrjLxfs> list = jtcyQb.list();
			for (TAppBfrjLxfs mTAppBfrjLxfs : list) {
				if (mTAppBfrjLxfs.getBbh() == bbh) {
					mTAppBfrjLxfs.setSjzt(AppUtil.sjzt_normal);
					jtcyDao.insertOrReplace(mTAppBfrjLxfs);
				} else {
					result = false;
				}
			}
		}
		
		return result;
	}
	
	/**
	 * 修改通话记录状态
	 * @param mList
	 * @return
	 */
	private boolean updateThjlByZt(List<TAppBfrjThjl> mList) {
		boolean result = true;
		
		if (mList == null || mList.size() == 0)
			return result;
		
		String jcuuid = mList.get(0).getJcuuid();

		TAppBfrjThjlDao dao = BankApplication.getDaoSession().getTAppBfrjThjlDao();
		String sql = "update " + dao.getTablename() + " set sjzt = " + AppUtil.sjzt_normal + " where jcuuid='"+jcuuid+"'";
		BankApplication.getDaoSession().getDatabase().execSQL(sql);
		
		return result;
	}
	
	// 获取字表数据更新状态
		public void getTAppBfrjBfjlStatus() {
			DaoSession session = BankApplication.getDaoSession();
			
			TAppBfrjBfjlDao bfjlDao = session.getTAppBfrjBfjlDao();
			TAppBfrjJtcybDao jtcyDao = session.getTAppBfrjJtcybDao();
			TAppBfrjCpxqDao cpxqDao = session.getTAppBfrjCpxqDao();
			TAppBfrjZcxxbDao zcxxDao = session.getTAppBfrjZcxxbDao();
			TAppBfrjLxfsDao lxfsDao = session.getTAppBfrjLxfsDao();
			TAppBfrjThjlDao thjlDao = session.getTAppBfrjThjlDao();
			
			//查询拜访信息
			QueryBuilder<TAppBfrjBfjl> bfrjqb = bfjlDao.queryBuilder();
			bfrjqb.whereOr(TAppBfrjBfjlDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjBfjlDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjBfjl> bfjList = bfrjqb.list();
			if(bfjList.size() != 0) {
				for(TAppBfrjBfjl item : bfjList) {
					setDataStatus(item.getJcuuid());
				}
			}
//			查询家庭信息
			QueryBuilder<TAppBfrjJtcyb> jtcyqb = jtcyDao.queryBuilder();
			jtcyqb.whereOr(TAppBfrjJtcybDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjJtcybDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjJtcyb> jtcyList = jtcyqb.list();
			if(jtcyList.size() != 0) {
				for(TAppBfrjJtcyb item : jtcyList) {
					setDataStatus(item.getJcuuid());
				}
			}
//			查询家庭信息
			QueryBuilder<TAppBfrjCpxq> cpxqqb = cpxqDao.queryBuilder();
			cpxqqb.whereOr(TAppBfrjCpxqDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjCpxqDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjCpxq> cpxqList = cpxqqb.list();
			if(cpxqList.size() != 0) {
				for(TAppBfrjCpxq item : cpxqList) {
					setDataStatus(item.getJcuuid());
				}	
			}
//			资产信息
			QueryBuilder<TAppBfrjZcxxb> zcxxqb = zcxxDao.queryBuilder();
			zcxxqb.whereOr(TAppBfrjZcxxbDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjZcxxbDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjZcxxb> zcxxList = zcxxqb.list();
			if(zcxxList.size() != 0) {
				for(TAppBfrjZcxxb item : zcxxList) {
					setDataStatus(item.getJcuuid());
				}	
			}
//			联系方式
			QueryBuilder<TAppBfrjLxfs> lxfsqb = lxfsDao.queryBuilder();
			lxfsqb.whereOr(TAppBfrjLxfsDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjLxfsDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjLxfs> lxfsList = lxfsqb.list();	
			if(lxfsList.size() != 0) {
				for(TAppBfrjLxfs item : lxfsList) {
					setDataStatus(item.getJcuuid());
				}	
			}
//			通话方式
			QueryBuilder<TAppBfrjThjl> thjlqb = thjlDao.queryBuilder();
			thjlqb.whereOr(TAppBfrjThjlDao.Properties.Sjzt.eq(AppUtil.sjzt_create), TAppBfrjThjlDao.Properties.Sjzt.eq(AppUtil.sjzt_update));
			List<TAppBfrjThjl> thjlList = thjlqb.list();
			if(thjlList.size() != 0) {
				for(TAppBfrjThjl item : thjlList) {
					setDataStatus(item.getJcuuid());
				}	
			}
		}
		
		public void  setDataStatus(String jcuuid) {
			//获取需要上传的客户信息
			TAppBfrjJbxxbDao dao = BankApplication.getDaoSession().getTAppBfrjJbxxbDao();
			QueryBuilder<TAppBfrjJbxxb> qb = dao.queryBuilder();
			qb.where(TAppBfrjBfjlDao.Properties.Uuid.eq(jcuuid));
			List<TAppBfrjJbxxb> thjlList = qb.list();
			if(thjlList.size() != 0) {
				for(TAppBfrjJbxxb item : thjlList) {
					item.setSjzt(AppUtil.sjzt_update);
					dao.insertOrReplace(item);
				}
			}
			
		}
		
}
